package com.sunshine.wrongquestionset.activity.question

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import com.sunshine.wrongquestionset.room.entity.*
import com.sunshine.wrongquestionset.room.repository.MyRepository

/**
 * @author sunshine
 * @date 2021/3/29
 */
class QuestionViewModel(application: Application): AndroidViewModel(application) {
    private val repository: MyRepository = MyRepository(application.applicationContext)

    fun getQuestionBySubject(subjectId: Int): LiveData<List<QuestionEntity>?> {
        return repository.getQuestionBySubject(subjectId)
    }

    fun getQuestionBySet(setId: Int): LiveData<List<QuestionEntity>?> {
        return repository.getAllQuestionInSetId(setId)
    }

    fun getAllQuestion(userId: String): LiveData<List<QuestionEntity>?> {
        return repository.getUserAllQuestion(userId)
    }

    fun getQuestionType(typeId: Int): LiveData<String?> {
        return repository.getTypeNameById(typeId)
    }

    fun deleteQuestion(questionEntity: QuestionEntity) {
        repository.deleteQuestionByEntity(questionEntity)
    }

    fun getQuestionInfoByQuestionId(questionId: Int): LiveData<List<QuestionInfoEntity>?> {
        return repository.getQuestionInfoByQuestionId(questionId)
    }

    fun getWrongQuestionBeanByQuestionId(questionId: Int): LiveData<List<WrongQuestionBean>?> {
        return repository.getWrongQuestionBeanByQuestionId(questionId)
    }

}